package com.glodon.paas.storage.ali;

import com.aliyun.common.auth.RequestSigner;
import com.aliyun.common.auth.ServiceCredentials;
import com.aliyun.common.auth.ServiceSignature;
import com.aliyun.common.comm.RequestMessage;
import com.aliyun.openservices.ClientException;

/**
 * this class is de-compiled from aliyun SDK
 * @author guojf
 *
 */
public class OSSRequestSigner implements RequestSigner {
	private String httpMethod;
	private String resourcePath;
	private ServiceCredentials credentials;

	public OSSRequestSigner(String paramString1, String paramString2,
			ServiceCredentials paramServiceCredentials) {
		assert (paramServiceCredentials != null);
		this.httpMethod = paramString1;
		this.resourcePath = paramString2;
		this.credentials = paramServiceCredentials;
	}

	public void sign(RequestMessage paramRequestMessage) throws ClientException {
		String str1 = this.credentials.getAccessKey();
		String str2 = this.credentials.getAccessId();
		if ((str2.length() > 0) && (str1.length() > 0)) {
			String str3 = SignUtils.buildCanonicalString(this.httpMethod,
					this.resourcePath, paramRequestMessage, null);
			String str4 = ServiceSignature.create()
					.computeSignature(str1, str3);
			paramRequestMessage.addHeader("Authorization", "OSS " + str2 + ":"
					+ str4);
		} else if (str2.length() > 0) {
			paramRequestMessage.addHeader("Authorization", str2);
		}
	}
}
